package com.sky;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;

import static java.lang.System.out;

public class t1 {
    public static void main(String[] args) {
        List<String> strings = Arrays.asList("cv", "abd", "aba", "efg", "abcd","jkl", "jkl");
        //reduce方法一
        Optional<String> reduce1 = strings.stream().reduce((acc, item) -> {return acc+item;});
        //reduce方法二
        String reduce2 = strings.stream().reduce("itcast", (acc, item) -> {
            return acc + item;
        });
        //reduce方法三
        ArrayList<String> reduce3 = strings.stream().reduce(
                new ArrayList<String>(),
                (acc, item) -> {
                    acc.add(item);
                    return acc;
                },
                (acc, item) -> acc
        );
        if(reduce1.isPresent())out.println(reduce1.get());
        out.println(reduce2);
        out.println(reduce3);
    }
}
